<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>首页展示数据</title>
<%@include file="../../head.jsp"%>

</head>
<body>
	
		

	<table id="list_data" cellspacing="0" cellpadding="0">  
    <thead>  
        <tr>
        		<th field="review" formatter="renderHomeItem">首页项管理</th>
       		    <th field="categoryName">类型名称</th>
				<th field="categoryUpdateTime" >创建时间</th>
					
		</tr>
    </thead>  
	</table>  
<script type="text/javascript">

 function renderHomeItem(value, row, index) {
	 return "<a href='${cpath }/admin/home/category/item/vlist?categoryId="
		+ row.categoryId +"&featureCategoryId="+row.featureCategoryId +"'>特色管理</a>";
	}
 
</script>

	<div id="addHomeCategory"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true">
	</div>
	
	<script type="text/javascript">
$('#list_data').datagrid({ 
    title:'首页展示的特色类别信息', 
    iconCls:'icon-edit',//图标 
    width: 1024, 
    height: 500,
    doSize:true,
    nowrap: false, 
    striped: true, 
    border: true, 
    collapsible:false,//是否可折叠的 
    fitColumns: true,//自动大小 
    fit:false,
    url:'${cpath }/admin/home/category/list', 
    //sortName: 'code', 
    //sortOrder: 'desc', 
    remoteSort:false,  
    idField:'categoryId', 
    singleSelect:true,//是否单选 
    pagination:true,//分页控件 
    rownumbers:true,//行号 
  
    toolbar: [
    { 
        text: '新增首页类型', 
        iconCls: 'icon-add', 
        handler: function() {
            var saveAction=cpath+'/admin/home/category/save';
            var openAction=cpath+'/admin/home/category/vsave';
        	openAddHomeCategory('添加首页类型信息',openAction,saveAction,successHomeCategory);
        } 
    },'-',
    { 
        text: '修改首页类型名称', 
        iconCls: 'icon-add', 
        handler: function() {
            var saveAction=cpath+'/admin/home/category/update';
            var openAction=cpath+'/admin/home/category/vupdate';
        	openUpdateHomeCategory('修改首页类型名称',openAction,saveAction,getSelectRow,successHomeCategory);
        } 
    }
    ,'-',{ 
        text: '删除首页类型', 
        iconCls: 'icon-remove', 
        handler: function() {
            var deleteAction =  cpath +'/admin/home/category/delete';
        	deleteHomeCategoryDialog(deleteAction,getSelectRow);
        } 
    }]
});
//设置分页控件 
var p = $('#list_data').datagrid('getPager'); 
$(p).pagination({ 
    pageSize: 10,//每页显示的记录条数，默认为10 
    pageList: [5,10,15],//可以设置每页记录条数的列表 
    beforePageText: '第',//页数文本框前显示的汉字 
    afterPageText: '页    共 {pages} 页', 
    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
    onBeforeRefresh:function(){
        $(this).pagination('loading');
        alert('before refresh');
        $(this).pagination('loaded');
    }
});  
</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';
		
		function getSelectRow(){
			return $('#list_data').datagrid('getSelected');
		}
		
		function successHomeCategory(){
			$('#list_data').datagrid('reload'); // reload the user data
		}
		
		function openAddHomeCategory(dlgtitle,openAction,saveAction,successHomeCategory){
			
			$('#addHomeCategory').dialog({
				title : dlgtitle,
				width : 800,
				height : 500,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveHomeCategory(saveAction, successHomeCategory);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addHomeCategory').dialog('close');
					}
				} ]
			});
			$('#addHomeCategory').dialog('open');
		}
		
		function openUpdateHomeCategory(dlgtitle,openAction,saveAction,getSelectRow,successHomeCategory){
			//添加信息，需要是否有前置条件
			if (getSelectRow) {

				var row = getSelectRow();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要修改的首页类型！", "info");
					return;
				}
				else
				{
					openAction = openAction+"?categoryId="+row.categoryId;
				}
			}
			$('#addHomeCategory').dialog({
				title : dlgtitle,
				width : 500,
				height : 300,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveHomeCategory(saveAction, successHomeCategory);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addHomeCategory').dialog('close');
					}
				} ]
			});
			$('#addHomeCategory').dialog('open');
		}
		var save_status = false;

		function saveHomeCategory(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result =  $(this).form('validate');
					if (!result){
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addHomeCategory').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}
		function deleteHomeCategoryDialog(deleteAction, getSelectRow) {
			//添加信息，需要是否有前置条件
			if (getSelectRow) {

				var row = getSelectRow();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的首页类型！", "info");
					return;
				}
				if (row) {
					$.messager.confirm("提示", "删除首页类型会一同删除该类型相关的首页项数据，确认要删除吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
	</script>
<style type="text/css">
			#fm {
				margin: 0;
				padding: 40px 40px;
			}
			
			.ftitle {
				font-size: 14px;
				font-weight: bold;
				padding: 5px 0;
				margin-bottom: 10px;
				border-bottom: 1px solid #ccc;
			}
			
			.fitem {
				margin-bottom: 5px;
			}
			
			.fitem label {
				display: inline-block;
				width: 90px;
			}
			
		 </style>
</body>
</html>